package demo1;
/**
 * 枪类
 */
public class Gun {
    private Clip clip;//弹夹
    public Gun(){
        this(null);
    }
    public Gun(Clip clip){
        this.clip = clip;
        //showGun();
    }
    //装弹夹
    public void loadClip(Clip clip){
        this.clip = clip;
        //showGun();
    }
    //开枪
    public void shootEnemy(Player enemy){
        if(clip == null){
            System.out.println(">>>枪械没有弹夹,放了一个空枪!");
            return;
        }
        Bullet bullet = clip.popBullet();
        if(bullet == null){
            System.out.println(">>>枪械的弹夹已空,放了一个空枪!");
            return;
        }
        bullet.hitEnemy(enemy);
    }
    //显示枪械信息
    public void showGun(){
        if(clip!=null){
            System.out.println(">>>枪械信息:有弹夹");
        }else{
            System.out.println(">>>枪械信息:无弹夹");
        }
    }
}

